# -*- coding: utf-8 -*-
# @Time : 2024/3/8 22:07
# @Author : Hami

from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes
import base64

class EncryptAes:
    def aes_encrypt(self, plaintext):
        """
        AES加密函数
        :param plaintext: 明文
        :param key: 密钥 (固定值)
        :return: Base64编码的密文
        """
        key = b'1234567812345678'
        cipher = AES.new(key, AES.MODE_ECB)
        ct_bytes = cipher.encrypt(pad(plaintext.encode('utf-8'), AES.block_size))  # encrypt 加密的方法
        text = base64.b64encode(ct_bytes).decode('utf-8')
        return text

ENCRYPTAES = EncryptAes()
# print(EncryptAes().aes_encrypt("tony"))
